package com.example.zm_fanjiantao.utils;

import com.example.zm_fanjiantao.enums.RestfullCode;

public class Result<T> {
    private int code;



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private String msg;
    private T data;

    private Result(RestfullCode restfullCode, T data) {
          this.code = restfullCode.getCode();
          this.msg = restfullCode.getMsg();
          this.data = data;
    }

    public Result(Integer code, String msg,T data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }



    //成功 枚举code
    public static <T> Result success(T data){
        return new Result(RestfullCode.SUCCESS,data);
    }

    //自定义code
    public static <T> Result success(RestfullCode restfullCode, T data){
        return new Result(restfullCode,data);
    }
//
//    //失败
    public static Result fail(){
        return new Result(RestfullCode.FAIL,"");
    }
    public static <T> Result fail(T msg){
        return new Result(RestfullCode.FAIL, msg);
    }
//
//    //自定义失败
//    public static Result fail(String msg){
//        return new Result(RestfullCode.FAIL.getCode(),msg);
//    }

}
